package edu.gdkm.dao;

import edu.gdkm.pojo.User;
import org.apache.ibatis.annotations.*;
import java.util.List;

public interface UserDAO {
    /**
     * 新增用户
     * @param user 用户对象
     * @return 是否成功
     */
    @Insert("INSERT INTO user(username, password, email, phone, user_type, avatar, status, create_time, update_time) " +
            "VALUES(#{username}, #{password}, #{email}, #{phone}, #{userType}, #{avatar}, #{status}, #{createTime}, #{updateTime})")
    boolean insert(User user);
    
    /**
     * 根据ID删除用户
     * @param id 用户ID
     * @return 是否成功
     */
    @Delete("DELETE FROM user WHERE id = #{id}")
    boolean deleteById(Long id);
    
    /**
     * 更新用户信息
     * @param user 用户对象
     * @return 是否成功
     */
    @Update("UPDATE user SET username = #{username}, password = #{password}, email = #{email}, phone = #{phone}, " +
            "user_type = #{userType}, avatar = #{avatar}, status = #{status}, update_time = #{updateTime} WHERE id = #{id}")
    boolean update(User user);
    
    /**
     * 根据ID查询用户
     * @param id 用户ID
     * @return 用户对象
     */
    @Select("SELECT * FROM user WHERE id = #{id}")
    User selectById(Long id);
    
    /**
     * 查询所有用户
     * @return 用户列表
     */
    @Select("SELECT * FROM user")
    List<User> selectAll();
    
    /**
     * 根据用户名查询用户
     * @param username 用户名
     * @return 用户对象
     */
    @Select("SELECT * FROM user WHERE username = #{username}")
    User selectByUsername(String username);
    
    /**
     * 根据邮箱查询用户
     * @param email 邮箱
     * @return 用户对象
     */
    @Select("SELECT * FROM user WHERE email = #{email}")
    User selectByEmail(String email);
}
